package group5_Project3;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class EmployeeForm extends PersonForm implements ActionListener{
	public String employeeID;
	private int salary;
	public String supervisor;
	static JFrame frame;
	static JPanel ePanel;
	static JPanel buttons;
	public static EmployeeForm e1;
	public static void main(String[] args){
		frame = new JFrame("Employee");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container pane = frame.getContentPane();
		pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
		JPanel ePanel = new JPanel(new GridLayout(0,2));
		ePanel = new JPanel(new GridLayout(0,2));

		ePanel.add(new JLabel("First Name:"));
		final JTextField fName = new JTextField();
		ePanel.add(fName);
		ePanel.add(new JLabel("Last Name:"));
		final JTextField lName = new JTextField(); 
		ePanel.add(lName);
		ePanel.add(new JLabel("SSN:"));
		final JTextField ssn = new JTextField();
		ePanel.add(ssn);
		ePanel.add(new JLabel("Age:"));
		final JTextField age = new JTextField();
		ePanel.add(age);
		ePanel.add(new JLabel("Employee ID:"));
		final JTextField employeeid1 = new JTextField();
		ePanel.add(employeeid1);
		ePanel.add(new JLabel("Salary:"));
		final JTextField salary1 = new JTextField();
		ePanel.add(salary1);
		ePanel.add(new JLabel("Supervisor:"));
		final JTextField supervisor1 = new JTextField();
		ePanel.add(supervisor1);
		frame.add(ePanel);

		JButton submit = new JButton("Submit");
		submit.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				int age1 = Integer.parseInt(age.getText());	
				int salary2 = Integer.parseInt(salary1.getText());

				e1 = new EmployeeForm(fName.getText(), lName.getText(), ssn.getText(), age1,
						employeeid1.getText(), salary2, supervisor1.getText()); 
			}
		});

		ePanel.add(submit);

		JButton cancel = new JButton("Cancel");
		cancel.addActionListener(new EmployeeForm());
		ePanel.add(cancel);
		frame.pack();
		frame.setVisible(true);
	}

	public EmployeeForm(){
	}
	public EmployeeForm(String firstname, String lastname, String ssn, int age, String employeeID, int salary, String supervisor){
		super(firstname, lastname, ssn, age);
		this.employeeID = employeeID;
		this.setSalary(salary);
		this.supervisor = supervisor;
		System.out.println(this);
		System.out.println("constructor called");
	}

	public int getSalary() 
	{
		return salary;
	}

	public void setSalary(int salary) 
	{
		this.salary = salary;
	} 

	@Override
	public String toString()
	{
		return (super.toString() + "\nEmployeeID: " + this.employeeID
				+ "\nSalary: " + this.getSalary() + "\nSupervisor: " + this.supervisor);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		System.exit(0);
	}
}
